#include "rewine/impl/CImage.hpp"

#include "misc/string_ext.hpp"

namespace rewine
{

bool
CImage::setExportName(const std::string& exportName) {
    int pos = exportName.rfind('.');
    if (pos == std::string::npos) {
        return false;
    }
    m_ExportName = to_lower_string(exportName);
    m_ModuleName = std::string_view(&m_ExportName.at(0), pos);
    return true;
}

bool
CImage::checkActivity() {
    if (isPinned()) {
        return true;
    }
    auto it = std::remove_if(m_ImportedBy.begin(), m_ImportedBy.end(), [](const imported_list_t::value_type& wp) {
        return wp.expired();
    });
    m_ImportedBy.erase(it, m_ImportedBy.end());
    return !m_ImportedBy.empty();
}

} // namespace rewine
